﻿<cfscript>
/** 
* DataBase Frameworks - Sequence
* 
* @hint "DataBase Frameworks - Sequence - WorkLoad" 
*/ 

component 
	displayname="public.service.db.senate.sequence.WorkLoad" 
	output=false 
	accessors=true 
	{

	property type="string" name="FunMethod" hint="绑定计算方法名称";
	
	/**
	* @hint "初始化对象"
	*/
	public function init() output=false {
		return this;
	}
	
	/**
	* @hint "自定义主键规则"
	*/
	public string function getID() output=false {
		
		var nextID = getFunMethod() & numberFormat(1, "0_");
		
		var sql = "SELECT a.fun_id 
					FROM t_workload_fun a  
					WHERE a.fun_id LIKE :condition 
					ORDER BY a.fun_id DESC";

		var queryObj = new Query(datasource = application.dnsMaster, maxRows = 1);
		queryObj.addParam( name="condition", value=getFunMethod() & "__" , cfsqltype="cf_sql_char" );
		var rs_check = queryObj.execute(sql = sql).getResult();


		/* 
			主键生成规则 CHAR(4)
			
			2位计算模版代码 2位流水号
		*/
		if (rs_check.recordCount) {
			/* 创建一个追加id */
			nextID = getFunMethod() & numberFormat((right(rs_check["fun_id"][1], 2) + 1), "0_");
			
		}

		return nextID;

	}

}

</cfscript>